package com.gt.web.srv.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class RequestUtil {
	public static final String X_REQUEST_ID = "X-Request-Id";
	public static final String TRACE_ID = "traceId";
	public static final String TOKEN_K = "token";

	private RequestUtil() {
	}

	public static HttpServletRequest getRequest() {
		RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
		if(requestAttributes == null) {
			return null;
		}
		return ((ServletRequestAttributes) requestAttributes).getRequest();
	}

	public static String getTraceId(HttpServletRequest request) {
		return request.getHeader(X_REQUEST_ID);
	}

	public static String getToken(HttpServletRequest request) {
		return request.getHeader(TOKEN_K);
	}
}
